<?php

/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Badge
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */

class Badge_AdminSettingsController extends Core_Controller_Action_Admin {
	public function indexAction() {
		$this->view->navigation = $navigation = Engine_Api::_ ()->getApi ( 'menus', 'core' )->getNavigation ( 'badge_admin_main', array (), 'badge_admin_main_settings' );
		$this->view->subNavigation = $this->getSubNavigation ();
		
		$this->view->form = $form = new Badge_Form_Admin_Global ();
		
		if ($this->getRequest ()->isPost () && $form->isValid ( $this->getRequest ()->getPost () )) {
			$values = $form->getValues ();
			
			foreach ( $values as $key => $value ) {
				Engine_Api::_ ()->getApi ( 'settings', 'core' )->setSetting ( $key, $value );
			}
			
			$savedChangesNotice = Zend_Registry::get ( 'Zend_Translate' )->_ ( "Your changes were saved." );
			$form->addNotice ( $savedChangesNotice );
		}
	}
	
	public function levelAction() {
		$this->view->navigation = $navigation = Engine_Api::_ ()->getApi ( 'menus', 'core' )->getNavigation ( 'badge_admin_main', array (), 'badge_admin_main_settings' );
		$this->view->subNavigation = $this->getSubNavigation ();
		
		$this->view->form = $form = new Badge_Form_Admin_Settings_Level ();
		
		if ($this->getRequest ()->isPost () && $form->isValid ( $this->getRequest ()->getPost () )) {
			$values = $form->getValues ();
			
			foreach ( $values as $key => $value ) {
				Engine_Api::_ ()->getApi ( 'settings', 'core' )->setSetting ( $key, $value );
			}
			
			$savedChangesNotice = Zend_Registry::get ( 'Zend_Translate' )->_ ( "Your changes were saved." );
			$form->addNotice ( $savedChangesNotice );
		}
	}
	
	public function networkAction() {
		$this->view->navigation = $navigation = Engine_Api::_ ()->getApi ( 'menus', 'core' )->getNavigation ( 'badge_admin_main', array (), 'badge_admin_main_settings' );
		$this->view->subNavigation = $this->getSubNavigation ();
		
		$this->view->form = $form = new Badge_Form_Admin_Settings_Network ();
		
		if ($this->getRequest ()->isPost () && $form->isValid ( $this->getRequest ()->getPost () )) {
			$values = $form->getValues ();
			
			foreach ( $values as $key => $value ) {
				Engine_Api::_ ()->getApi ( 'settings', 'core' )->setSetting ( $key, $value );
			}
			
			$savedChangesNotice = Zend_Registry::get ( 'Zend_Translate' )->_ ( "Your changes were saved." );
			$form->addNotice ( $savedChangesNotice );
		}
	}
	
	public function profileAction() {
		$this->view->navigation = $navigation = Engine_Api::_ ()->getApi ( 'menus', 'core' )->getNavigation ( 'badge_admin_main', array (), 'badge_admin_main_settings' );
		$this->view->subNavigation = $this->getSubNavigation ();
		
		$this->view->form = $form = new Badge_Form_Admin_Settings_Profile ();
		
		if ($this->getRequest ()->isPost () && $form->isValid ( $this->getRequest ()->getPost () )) {
			$values = $form->getValues ();
			
			foreach ( $values as $key => $value ) {
				Engine_Api::_ ()->getApi ( 'settings', 'core' )->setSetting ( $key, $value );
			}
			
			$savedChangesNotice = Zend_Registry::get ( 'Zend_Translate' )->_ ( "Your changes were saved." );
			$form->addNotice ( $savedChangesNotice );
		}
	}
	
	protected function getSubNavigation() {
		
		$navigation = new Zend_Navigation ();
		
		$navigation->addPage ( array ('label' => Zend_Registry::get ( 'Zend_Translate' )->_ ( 'Global Settings' ), 'route' => 'admin_default', 'module' => 'badge', 'controller' => 'settings', 'action' => 'index' ) );
		
		$navigation->addPage ( array ('label' => Zend_Registry::get ( 'Zend_Translate' )->_ ( 'Member Level Mapping' ), 'route' => 'admin_default', 'module' => 'badge', 'controller' => 'settings', 'action' => 'level' ) );
		
		$navigation->addPage ( array ('label' => Zend_Registry::get ( 'Zend_Translate' )->_ ( 'Network Mapping' ), 'route' => 'admin_default', 'module' => 'badge', 'controller' => 'settings', 'action' => 'network' ) );
		
		$navigation->addPage ( array ('label' => Zend_Registry::get ( 'Zend_Translate' )->_ ( 'Profile Type Mapping' ), 'route' => 'admin_default', 'module' => 'badge', 'controller' => 'settings', 'action' => 'profile' ) );
		
		return $navigation;
	}

}